<?php

// $str ="445281198611251877";

// $str ="445281180107251526";

// $preg = "/^[1-9]\d{5}(1[89]\d{2}|20(0\d|1[0-8]))(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/";

// // ^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$

// // ^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$


// $email = "113@a.cc.net";

// $email = "113@bai-du.com";

// // 6~18个字符，可使用字母、数字、下划线，需以字母开头


// $preg = "/^[a-z]\w{5,17}@[a-z\d]+(\.[a-z]{2,})+$/";

// // $preg  ="/^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/";

// $c = preg_match($preg,$email);

// var_dump($c);




// var_dump($data);

function curl_get($url, $gzip=false){
	$curl = curl_init($url);
	$header = array (
            "Host:news.haiwainet.cn",
            "Content-Type:application/x-www-form-urlencoded",//post请求
            "Connection: keep-alive",
            'Referer:http://news.haiwainet.cn/',
            'User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; BIDUBrowser 2.6)'
        );
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt ($curl, CURLOPT_HTTPHEADER, $header );
	curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
	if($gzip) curl_setopt($curl,CURLOPT_ENCODING, "gzip"); 
	$content = curl_exec($curl);
	curl_close($curl);
	return $content;
}

// exit;
$data = curl_get('http://news.haiwainet.cn/yuanchuang/',true);

// $data = file_get_contents("compress.zlib://"."http://news.haiwainet.cn/yuanchuang/");

$preg = "/<a href=\"(.+?)\" target=\"_blank\" title=\".+?\">(.+?)<\/a> <span>.+?<\/span>/";


$c = preg_match_all($preg,$data,$out);

$urllist = $out[1];

$urllist = array_slice($urllist, 0,10);

// var_dump($urllist);exit;


$atrList = [];

foreach ($urllist as $k => $url) {
	$temp = [];

	// $data = curl_get($url,true);

	$data = file_get_contents("compress.zlib://".$url);

	$title = "/<h1 class=\"show_wholetitle\">(.+?)<\/h1>/";

	$c = preg_match_all($title,$data,$out);

	$temp['nickname'] = $out[1][0];


	$title = "/<span class=\"first\">(.+?)<\/span>/";

	$c = preg_match_all($title,$data,$out);

	$temp['ctime'] = $out[1][0];

	$content = "/class=\"contentMain\">(.+?)<p class=\"writer\"/s";

	$c = preg_match_all($content,$data,$out);

	$temp['content'] = $out[1][0];

	$atrList[] = $temp;

}
var_dump($atrList);

